package com.u17;

/**
 * @author u17
 * https://leetcode-cn.com/problems/remove-element/
 */
public class Solution {

    /**
     * 快慢指针
     * @param nums
     * @param val
     * @return
     */
    public int removeElement(int[] nums, int val) {
        int n = nums.length;
        int fast = 0;
        int low = 0;

        while (fast < n) {
            if (nums[fast] != val) {
                nums[low++] = nums[fast];
            }
            fast++;
        }
        return low;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = new int[]{3, 2, 2, 3};
        int val = 3;
        System.out.println(solution.removeElement(nums, val));
    }
}
